<?php
/**
 * Created by PhpStorm.
 * User: MR_THONG
 * Date: 2/3/2015
 * Time: 8:14 AM
 */
App::uses('AppController', 'Controller');
class MypagesController extends AppController {
        public function tourdetails($tourkindid){
            $this->loadModel('TourKind');
            $tourdetail = $this->TourKind->findById($tourkindid);
            $this->set('tourdetail', $tourdetail);
            $this->loadHeaderData();
        }

        public function supportservice($supportServiceId) {
            $this->loadHeaderData();
            $supportServiceDetail = $this->SupportService->findById($supportServiceId);
            $this->set('supportServiceDetail',$supportServiceDetail);

        }

        public function supportinformation() {
            $this->loadHeaderData();
            $params = $this->data;
            $this->loadModel('CustomerSupport');
            $this->CustomerSupport->set('customername',$params['Post']['customername']);
            $this->CustomerSupport->set('customeremail',$params['Post']['customeremail']);
            $this->CustomerSupport->set('customerphone',$params['Post']['customerphone']);
            $this->CustomerSupport->set('customercompany',$params['Post']['customercompany']);
            $this->CustomerSupport->set('customeraddress',$params['Post']['customeraddress']);
            $this->CustomerSupport->set('customerrequest',$params['Post']['customerrequest']);
            $this->CustomerSupport->save();
        }

        public function searchtour(){
            //$tapeexists = $this->Tape->find('all', array('conditions'=>array('Tape.name LIKE'=>'blondie%')));
            $this->loadModel('Tour');
            $params = $this->data;
            $searchparams = $params['post']['tourname'];
            $toursearched = $this->Tour->find('all', array('conditions'=>array('Tour.title LIKE'=>'%'.$searchparams.'%')));
            $this->set('toursearched',$toursearched);

            $this->loadHeaderData();

        }

        public function tourdetaildisplay($tourid){

            $this->loadHeaderData();

            $this->loadModel('Tour');
            $tourDisplay = $this->Tour->findById($tourid);
            $this->set('tourDisplay',$tourDisplay);
        }
        public function normaltour(){
            //Load Normal Tour
            $this->loadModel('Tour');
            $this->Paginator->settings = $this->paginate;
            $normalTour = $this->Paginator->paginate(
                'Tour'
            );
            $this->set('normalTour', $normalTour);
            $this->layout = null;
            $this->render('/Elements/normal_tour');
        }
        public function highlighttour(){
            //Load HighLight Tour
            $this->loadModel('Tour');
            $this->Paginator->settings = $this->paginateHightLightTour;
            $hightlightTour = $this->Paginator->paginate(
                'Tour'
            );
            $this->set('hightlightTour', $hightlightTour);
            $this->layout = null;
            $this->render('/Elements/high_light_tour');
        }

        public function index(){
            // Nghia: set title page
            $this->set('title_for_layout', 'Trang Chủ');
            // end Nghia
            //Load All Model
            $this->loadModel('TourKind');
            $this->loadModel('Tour');
            $this->loadModel('CateArtical');

            $this->loadHeaderData();

//            //Load Support Services
//            $this->loadModel('SupportService');
//            $supportServices = $this->SupportService->find('all',array(
//                'order' => array('SupportService.id' => 'asc')
//            ));
//            $this->set('supportServices', $supportServices);

            //Load newest Foreign Tour
            $newest_foriegn_tour = $this->Tour->find('first', array(
                'conditions' => array('Tour.is_national' => 0),
                'order' => array('Tour.created_date' => 'desc')
            ));
            $this->set('newestForiegnTour', $newest_foriegn_tour);

            //Load newest National Tour
            $newest_national_tour = $this->Tour->find('first', array(
                'conditions' => array('Tour.is_national' => 1),
                'order' => array('Tour.created_date' => 'desc')
            ));
            $this->set('newestNationalTour', $newest_national_tour);

            //Load HightLight Tour
            $this->Paginator->settings = $this->paginateHightLightTour;
            $hightlightTour = $this->Paginator->paginate(
                'Tour'
            );
            //Count number of HighLight Tour
            $highlightTourNum = $this->Tour->find('count', array(
                'conditions' => array('Tour.is_hightlight' => '1')
            ));
            $this->set('hightlightTour', $hightlightTour);
            $this->set('highlightTourNum', $highlightTourNum);

            //Load Normal Tour
            $this->Paginator->settings = $this->paginate;
            $normalTour = $this->Paginator->paginate(
                'Tour'
            );
            //Count number of Normal Tour
            $normalTourNum = $this->Tour->find('count', array(
                'conditions' => array('Tour.is_hightlight' => '0')
            ));
            $this->set('normalTour', $normalTour);
            $this->set('normalTourNum', $normalTourNum);

            //Load 8 tour national
            $tour = $this->Tour->find('all', array(
                'conditions' => array('Tour.is_national' => 1),
                'order' => array('Tour.created_date' => 'desc'),
                'limit' => 5,
            ));
            $this->set('tour', $tour);

            //Load 8 tour International
            $tourInternational = $this->Tour->find('all', array(
                'conditions' => array('Tour.is_national' => 0),
                'order' => array('Tour.created_date' => 'desc'),
                'limit' => 5
            ));
            $this->set('tourInternational', $tourInternational);

            //Load Artical
            $articalTitle = $this->CateArtical->find('all',array());
            $this->set('articalTitle', $articalTitle);
    }

    public $components = array('Paginator');
    public $paginate = array(
        'conditions' => array('Tour.is_hightlight' => 0),
        'limit' => 8,
        'order' => array('Tour.created_date' => 'desc')
    );
    public $paginateHightLightTour = array(
        'conditions' => array('Tour.is_hightlight' => 1),
        'limit' => 8,
        'order' => array('Tour.created_date' => 'desc')
    );

    public function tourindex($tourid){


    }
}